﻿using System.Collections.Generic;
using MugenInjection.Bindings.Builders;
using MugenInjection.Interface;

namespace MugenInjection.Infrastructure
{
    /// <summary>
    ///     Contain constant key for special parameter.
    /// </summary>
    public static class SpecialParameterKeys
    {
        #region Binding values

        /// <summary>
        ///    Represents the key that responds to try dispose object in bindings.
        /// </summary>
        public static readonly string TryDisposeObjectSetting = "_TryDisposeObjectSetting_";

        /// <summary>
        ///      Represents the key key for named binding.
        /// </summary>
        public static readonly string KeyedBindingParameter = "_KeyedBindingParameter_";

        /// <summary>
        ///      Represents the key key for no cache binding.
        /// </summary>
        public static readonly string NoCacheBindingKey = "_NoCacheBindingKey_";

        #endregion

        #region Methods

        /// <summary>
        /// Sets the setting to dictionary that indicates that it a named binding. 
        /// </summary>
        /// <param name="specialParameters">The specified <see cref="IDictionary{TKey,TValue}"/></param>
        /// <param name="key">The specified binding key.</param>
        public static void SetKeyedBindingParameter(IDictionary<string, object> specialParameters, object key)
        {
            Validate.ArgumentNotNull(specialParameters, "specialParameters");
            Validate.ArgumentNotNull(key, "key");
            specialParameters[KeyedBindingParameter] = key;
        }

        /// <summary>
        /// Sets the setting to not cache specified binding.
        /// </summary>
        /// <returns>The fluent syntax.</returns>
        public static T NotCache<T>(
#if !NET2
this
#endif
T builder) where T : IBindingBuilder
        {
            IDictionary<string, object> settings;
            if (builder.Settings.TryGet(BindingBuilderConfigurator.BindingSettingsKey, out settings))
                settings[NoCacheBindingKey] = true;
            return builder;
        }

        #endregion
    }
}